import com.bdqn.t382.entity.Printer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PrinterTest2 {
    private static final Logger logger = LoggerFactory.getLogger(PrinterTest.class);

    public static void main(String[] args) {
        logger.info("开始测试打印机");
        // 加载 Spring 配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 获取彩色打印机
        Printer colorPrinter = (Printer) context.getBean("colorPrinter");
        try {
            colorPrinter.print("这是彩色墨盒在 A4 纸上的打印测试。");
        } catch (Exception e) {
            // 异常已经在切面中处理，这里可以不做额外处理
        }

        // 获取灰色打印机
        Printer grayPrinter = (Printer) context.getBean("grayPrinter");
        try {
            grayPrinter.print("这是灰色墨盒在 B5 纸上的打印测试。");
        } catch (Exception e) {
            // 异常已经在切面中处理，这里可以不做额外处理
        }

        // 关闭 Spring 上下文
        ((ClassPathXmlApplicationContext) context).close();
        logger.info("测试结束");
    }

}
